<template>
	<view>
		<uni-nav-bar :fixed="true" left-icon="back" color="#156DAC" @clickLeft="pageback">
			<view class="header-icon-text-panel">
				<text class="title">客户信息</text>
			</view>
		</uni-nav-bar>
		<view class="content padding">
			<form class="user-form" :disabled="true">
				<view class="card">
					<view class="user-form-item">
						<view class="form-label">企业名称</view>
						<view class="form-input desc" style="height: auto;">
							{{formObj.name}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">企业简称</view>
						<view class="form-input desc">
							{{formObj.enterpriseShort || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">所属项目部</view>
						<view class="form-input desc">
							{{formObj.projectDepartmentName || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">组织机构代码</view>
						<view class="form-input desc">
							{{formObj.organizationCode || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">法人代表</view>
						<view class="form-input desc">
							{{formObj.legalRepresentative || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">企业地址</view>
						<view class="form-input desc" style="height: auto;">
							{{formObj.enterpriseAddressDetails || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">邮编</view>
						<view class="form-input desc">
							{{formObj.zipCode || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">传真</view>
						<view class="form-input desc">
							{{formObj.fax || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">联系人</view>
						<view class="form-input desc">
							{{formObj.contacts || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">联系方式</view>
						<view class="form-input desc">
							{{formObj.contactInformation || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">排放类型</view>
						<view class="form-input desc">
							{{formObj.emissionTypeVal || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">控制级别</view>
						<view class="form-input desc">
							{{formObj.controlLevelVal || '- -'}}
						</view>
					</view>
					<view class="user-form-item">
						<view class="form-label">行业类别</view>
						<view class="form-input desc">
							{{formObj.industryCategoryVal || '- -'}}
						</view>
					</view>
				</view>
			</form>
		</view>
		<ourLoading isFullScreen color="#156dac" :active="businessLoading" />
	</view>
</template>
<script>
	import uniIcons from "@/components/uni-icons/uni-icons.vue"
	import uniPopup from "@/components/uni-popup/uni-popup.vue"
	import ourLoading from '@/components/our-loading/our-loading.vue'
	import uniSteps from '@/components/uni-steps/uni-steps.vue'
	import {getDict} from '@/common/dict.js'
	
	const getById = '/base/enterprise'
	const getdeptById = '/base/department'
	
	export default {
		components: {
			uniIcons,uniPopup,ourLoading,uniSteps
		},
		data() {
			return {
				isDetail: false,
				type: '',
				businessLoading: false,
				formObj: {
					id: null,
					name: null,
					enterpriseShort: null,
					projectDepartmentId: null,
					organizationCode: null,
					legalRepresentative: null,
					zipCode: null,
					fax: null,
					contacts: null,
					contactInformation: null,
					emissionType: null,
					controlLevel: null,
					industryCategory: null,
					enterpriseLocation: null,
					enterpriseAddressDetails: null,
					addressPId: null,
					enterpriseCityId: null,
					enterpriseAddressId: null,
					projectDepartmentName: null
				},
			}
		},
		onLoad(option) {
			const id = option.id
			if(id){
				this.businessLoading = true
				this.$api.request(`${getById}/${id}`,{
					method: 'get',
				}).then(res=>{
					//this.businessLoading = false
					if(res.success){
						let data = res.data.obj
						// 字典
						let e012 = getDict('e012')
						for(let i=0;i<e012.length;i++){
							if(data.emissionType === e012[i].code){
								data.emissionTypeVal = e012[i].codeName
								break
							}
						}
						let e013 = getDict('e013')
						for(let j=0; j<e013.length;j++){
							if(data.industryCategory === e013[j].code){
								data.industryCategoryVal = e013[j].codeName
								break
							}
						}
						let e014 = getDict('e014')
						for(let k=0; k<e014.length;k++){
							if(data.controlLevel === e014[k].code){
								data.controlLevelVal = e014[k].codeName
								break
							}
						}
						this.formObj = data
						
						
						
						
						
						let deptId = this.formObj.projectDepartmentId
						this.$api.request(`${getdeptById}/${deptId}`,{
							method: 'get',
						}).then(res=>{
							this.businessLoading = false
							if(res.success){
								this.formObj.projectDepartmentName = res.data.obj.name
							}
						}).catch(()=>{
							this.businessLoading = false
						})
					}else{
						this.$api.toastMsg(res.message)
						this.businessLoading = false
					}
				}).catch(()=>{
					this.businessLoading = false
				})
				
			}
			this.isDetail = option.type === 'detail'
			this.type = option.type
		},
		methods: {
			toggle(){
				this.$refs.popup.open()
			},
			pageback(){
				uni.navigateBack({
					delta: 1
				});
			},
			tableChange(e){
				console.log(e.detail)
			},
			setTableData(e,index){
				console.log(e.detail.value,index)
				this.$set(this.tableValue,index,e.detail.value)
			},
		}
	}
</script>

<style lang="scss" scoped>
.popup-content {
	background-color: #fff;
	padding: 15px;
}

</style>
